package com.java.controller;

import com.alibaba.fastjson.JSONObject;
import com.java.sevice.TransferService;
import com.java.utils.HttpParamUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @author xulu
 * @date 2019/6/13 16:26
 * @description: TODO
 */
@RestController
@Api(tags = "提供测试接口")
@RequestMapping(value = "/transferMoney")
public class TestController {
    @Autowired
    private TransferService transferService;

    @GetMapping(value = "/")
    public Object def() {
        return "hello world";
    }

    @PostMapping(value = "/transferMoney")
    public Object transferMoney(@RequestBody String param) throws Exception {
        JSONObject json = HttpParamUtil.paramToJson(param);
        Long accountId = json.getLong("accountId");
        BigDecimal amount = json.getBigDecimal("amount");
        return transferService.transferMoney(accountId, amount);
    }

}
